using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using Common;

namespace PCR.PCRControls
{
	public partial class HRM : UserControl, ISection, INotifyPropertyChanged, IComponentConnector
	{
		public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(HRM), new FrameworkPropertyMetadata(false, OnIsSelectedChanged));

		private bool Click;

		private string _SectName = Utility.GetMessage("section_hrm");

		private string _StepName = Section.DefaultStepName;

		private double _TestTempt = 0.2;

		private bool TestTemptEditClick;

		private double _TemptRate = 0.02;

		private bool TemptRateEditClick;

		private int _StaySecond = 15;

		private bool StaySecondEditClick;

		public static readonly DependencyProperty PriorTemptProperty = DependencyProperty.Register("PriorTempt", typeof(double), typeof(HRM), new FrameworkPropertyMetadata(25.0, OnPriorTemptChanged));

		public static readonly DependencyProperty StartTemptProperty = DependencyProperty.Register("StartTempt", typeof(double), typeof(HRM), new FrameworkPropertyMetadata(51.5, OnStartTemptChanged));

		private bool StartTemptEditClick;

		public static readonly DependencyProperty EndTemptProperty = DependencyProperty.Register("EndTempt", typeof(double), typeof(HRM), new FrameworkPropertyMetadata(51.5, OnEndTemptChanged));

		private bool EndTemptEditClick;

		private int _Type;

		private bool _ScreenTest = true;

		public bool IsSelected
		{
			get
			{
				return (bool)GetValue(IsSelectedProperty);
			}
			set
			{
				SetValue(IsSelectedProperty, value);
			}
		}

		public string SectName
		{
			get
			{
				return _SectName;
			}
			set
			{
				if (_SectName != value && value != null)
				{
					_SectName = value.Trim();
					OnPropertyChanged("SectName");
				}
			}
		}

		public string StepName
		{
			get
			{
				return _StepName;
			}
			set
			{
				if (_StepName != value && value != null)
				{
					_StepName = value.Trim();
					OnPropertyChanged("StepName");
				}
			}
		}

		public double TestTempt
		{
			get
			{
				return _TestTempt;
			}
			set
			{
				if (value < 0.2)
				{
					value = 0.2;
				}
				if (value > 1.0)
				{
					value = 1.0;
				}
				if (value != _TestTempt)
				{
					_TestTempt = value;
					OnPropertyChanged("TestTempt");
				}
			}
		}

		public double TemptRate
		{
			get
			{
				return _TemptRate;
			}
			set
			{
				if (value < 0.01)
				{
					value = 0.01;
				}
				if (value > 0.05)
				{
					value = 0.05;
				}
				if (value != _TemptRate)
				{
					_TemptRate = value;
					OnPropertyChanged("TemptRate");
				}
			}
		}

		public int StaySecond
		{
			get
			{
				return _StaySecond;
			}
			set
			{
				if (value < 7)
				{
					value = 7;
				}
				if (value > 30)
				{
					value = 30;
				}
				if (_StaySecond != value)
				{
					_StaySecond = value;
					OnPropertyChanged("StaySecond");
				}
			}
		}

		public double PriorTempt
		{
			get
			{
				return (double)GetValue(PriorTemptProperty);
			}
			set
			{
				if ((double)GetValue(PriorTemptProperty) != value)
				{
					SetValue(PriorTemptProperty, value);
					OnPropertyChanged("PriorTempt");
				}
			}
		}

		public double StartTempt
		{
			get
			{
				return (double)GetValue(StartTemptProperty);
			}
			set
			{
				if (value < 4.0)
				{
					value = 4.0;
				}
				if (value > 99.0)
				{
					value = 99.0;
				}
				SetValue(StartTemptProperty, value);
			}
		}

		public double EndTempt
		{
			get
			{
				return (double)GetValue(EndTemptProperty);
			}
			set
			{
				if (value < 4.0)
				{
					value = 4.0;
				}
				if (value > 99.0)
				{
					value = 99.0;
				}
				SetValue(EndTemptProperty, value);
			}
		}

		public int Type
		{
			get
			{
				return _Type;
			}
			set
			{
				if (value != _Type)
				{
					_Type = value;
					OnPropertyChanged("Type");
				}
			}
		}

		public bool ScreenTest
		{
			get
			{
				return _ScreenTest;
			}
			set
			{
				if (_ScreenTest != value)
				{
					_ScreenTest = value;
					OnPropertyChanged("ScreenTest");
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		public HRM()
		{
			InitializeComponent();
			StartTempt = 60.0;
			EndTempt = 90.0;
			TestTempt = 0.2;
			StaySecond = 10;
			TemptRate = 0.01;
		}

		public void OnPropertyChanged(string propName)
		{
			if (string.IsNullOrEmpty(propName))
			{
				throw new ArgumentException("propName");
			}
			if (this.PropertyChanged != null)
			{
				this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
			}
		}

		private static void OnIsSelectedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			HRM hRM = obj as HRM;
			if (hRM.IsSelected)
			{
				hRM.Background = new SolidColorBrush(Colors.LightPink);
			}
			else
			{
				hRM.Background = new SolidColorBrush(Colors.Transparent);
			}
		}

		private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			Click = true;
		}

		private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (Click)
			{
				Click = false;
				IsSelected = !IsSelected;
			}
		}

		private void TestTemptEdit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			TestTemptEditClick = true;
			e.Handled = true;
		}

		private void TestTemptEdit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (TestTemptEditClick)
			{
				TestTemptEditClick = false;
				cTestTempt.Visibility = Visibility.Visible;
				cTestTempt.Focus();
				cTestTempt1.Visibility = Visibility.Collapsed;
			}
		}

		private void cTestTempt_LostFocus(object sender, RoutedEventArgs e)
		{
			cTestTempt1.Visibility = Visibility.Visible;
			cTestTempt.Visibility = Visibility.Collapsed;
		}

		private void TemptRateEdit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			TemptRateEditClick = true;
			e.Handled = true;
		}

		private void TemptRateEdit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (TemptRateEditClick)
			{
				TemptRateEditClick = false;
				cTemptRate.Visibility = Visibility.Visible;
				cTemptRate.Focus();
				cTemptRate1.Visibility = Visibility.Collapsed;
			}
		}

		private void cTemptRate_LostFocus(object sender, RoutedEventArgs e)
		{
			cTemptRate1.Visibility = Visibility.Visible;
			cTemptRate.Visibility = Visibility.Collapsed;
		}

		private void StaySecondEdit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			StaySecondEditClick = true;
			e.Handled = true;
		}

		private void StaySecondEdit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (StaySecondEditClick)
			{
				StaySecondEditClick = false;
				cStaySecond.Visibility = Visibility.Visible;
				cStaySecond.Focus();
				cStaySecond1.Visibility = Visibility.Collapsed;
			}
		}

		private void cStaySecond_LostFocus(object sender, RoutedEventArgs e)
		{
			cStaySecond1.Visibility = Visibility.Visible;
			cStaySecond.Visibility = Visibility.Collapsed;
		}

		private static void OnPriorTemptChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
		}

		private static void OnStartTemptChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			HRM hRM = obj as HRM;
			hRM.StartTempt = hRM.StartTempt;
			hRM.cStartMarginTop.Height = new GridLength(99.0 - hRM.StartTempt, GridUnitType.Star);
			hRM.cStartMarginBot.Height = new GridLength(hRM.StartTempt - 4.0, GridUnitType.Star);
		}

		private void StartGridSplitter_DragDelta(object sender, DragDeltaEventArgs e)
		{
			double num = cStartMarginBot.ActualHeight + cStartMarginTop.ActualHeight;
			if (num <= 0.0)
			{
				num = 1.0;
			}
			StartTempt = Convert.ToInt16(cStartMarginBot.ActualHeight / num * 95.0) + 4;
			BindingExpression bindingExpression = cStartTempt.GetBindingExpression(NumSpan.ValueProperty);
			if (bindingExpression != null)
			{
				bindingExpression.UpdateSource();
			}
		}

		private void StartTemptEdit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			StartTemptEditClick = true;
			e.Handled = true;
		}

		private void StartTemptEdit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (StartTemptEditClick)
			{
				StartTemptEditClick = false;
				cStartTempt.Visibility = Visibility.Visible;
				cStartTempt.Focus();
				cStartTempt1.Visibility = Visibility.Collapsed;
			}
		}

		private void cStartTempt_LostFocus(object sender, RoutedEventArgs e)
		{
			cStartTempt1.Visibility = Visibility.Visible;
			cStartTempt.Visibility = Visibility.Collapsed;
		}

		private static void OnEndTemptChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			HRM hRM = obj as HRM;
			hRM.EndTempt = hRM.EndTempt;
			hRM.cEndMarginTop.Height = new GridLength(99.0 - hRM.EndTempt, GridUnitType.Star);
			hRM.cEndMarginBot.Height = new GridLength(hRM.EndTempt - 4.0, GridUnitType.Star);
		}

		private void EndGridSplitter_DragDelta(object sender, DragDeltaEventArgs e)
		{
			double num = cEndMarginBot.ActualHeight + cEndMarginTop.ActualHeight;
			if (num <= 0.0)
			{
				num = 1.0;
			}
			EndTempt = Convert.ToInt16(cEndMarginBot.ActualHeight / num * 95.0) + 4;
			BindingExpression bindingExpression = cEndTempt.GetBindingExpression(NumSpan.ValueProperty);
			if (bindingExpression != null)
			{
				bindingExpression.UpdateSource();
			}
		}

		private void EndTemptEdit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			EndTemptEditClick = true;
			e.Handled = true;
		}

		private void EndTemptEdit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (EndTemptEditClick)
			{
				EndTemptEditClick = false;
				cEndTempt.Visibility = Visibility.Visible;
				cEndTempt.Focus();
				cEndTempt1.Visibility = Visibility.Collapsed;
			}
		}

		private void cEndTempt_LostFocus(object sender, RoutedEventArgs e)
		{
			cEndTempt1.Visibility = Visibility.Visible;
			cEndTempt.Visibility = Visibility.Collapsed;
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		internal Delegate _CreateDelegate(Type delegateType, string handler)
		{
			return Delegate.CreateDelegate(delegateType, this, handler);
		}
	}
}
